Skip to content

fix: use None instead of mutable default for tools parameter#159

Merged
adambalogh merged 1 commit intoOpenGradient:mainfrom
adambalogh:fix/mutable-default-argument
Feb 17, 2026
Merged

fix: use None instead of mutable default for tools parameter#159
adambalogh merged 1 commit intoOpenGradient:mainfrom
adambalogh:fix/mutable-default-argument

Conversation

@adambalogh
Copy link
Collaborator

Summary

The chat() method in src/opengradient/client/llm.py used a mutable default argument:

tools: Optional[List[Dict]] = []

This is a known Python anti-pattern that can cause shared state across function calls, leading to subtle and hard-to-debug issues.

Fix

Changed to the safe pattern:

tools: Optional[List[Dict]] = None

The existing code already handles None correctly since it uses if tools: which evaluates to False for both [] and None.

Related

Fixes item #5 from issue #157.

@adambalogh adambalogh merged commit 1fa6a56 into OpenGradient:main Feb 17, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant